<?php

namespace App\Http\Controllers\Rank;

use App\Models\Repository;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;

class RepositoriesLength extends Controller
{
    /**
     * Handle the incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function __invoke(Request $request)
    {
        $repositories = DB::table('repositories')->select(['title','length'])->where('type','!=',Repository::TYPE_HIDDEN)->orderByDesc('length')->limit(5)->get()->map(function (
            $item
        ) {
            return [$item->title, $item->length.'字'];
        });
        return view('resources.rank.repositories-length')->with('repositories', $repositories);
    }
}
